{% extends "base.html" %}

{% block content %}
<div class="container">
    <h2>售后服务列表</h2>
    
    <div class="card mb-4">
        <div class="card-body">
            <form method="GET" class="row g-3">
                <div class="col-md-3">
                    <input type="text" class="form-control" name="order_id" placeholder="订单号" value="{{ order_id }}">
                </div>
                <div class="col-md-3">
                    <input type="text" class="form-control" name="customer_name" placeholder="客户名称" value="{{ customer_name }}">
                </div>
                <div class="col-md-2">
                    <select class="form-select" name="service_type">
                        <option value="">服务类型</option>
                        <option value="complaint" {% if service_type == 'complaint' %}selected{% endif %}>投诉</option>
                        <option value="return" {% if service_type == 'return' %}selected{% endif %}>退货</option>
                        <option value="repair" {% if service_type == 'repair' %}selected{% endif %}>维修</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <select class="form-select" name="status">
                        <option value="">状态</option>
                        <option value="pending" {% if status == 'pending' %}selected{% endif %}>待处理</option>
                        <option value="processing" {% if status == 'processing' %}selected{% endif %}>处理中</option>
                        <option value="completed" {% if status == 'completed' %}selected{% endif %}>已完成</option>
                        <option value="closed" {% if status == 'closed' %}selected{% endif %}>已关闭</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">搜索</button>
                </div>
            </form>
        </div>
    </div>

    <div class="mb-3">
        <a href="{{ url_for('service.service_add') }}" class="btn btn-success">
            <i class="fas fa-plus"></i> 新增服务记录
        </a>
    </div>

    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>订单号</th>
                    <th>客户名称</th>
                    <th>服务类型</th>
                    <th>优先级</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for service in services %}
                <tr>
                    <td>{{ service.order_id }}</td>
                    <td>{{ service.customer_name }}</td>
                    <td>
                        {% if service.service_type == 'complaint' %}投诉
                        {% elif service.service_type == 'return' %}退货
                        {% elif service.service_type == 'repair' %}维修
                        {% endif %}
                    </td>
                    <td>
                        {% if service.priority == 'urgent' %}
                            <span class="badge bg-danger">紧急</span>
                        {% elif service.priority == 'high' %}
                            <span class="badge bg-warning">高</span>
                        {% elif service.priority == 'normal' %}
                            <span class="badge bg-info">普通</span>
                        {% else %}
                            <span class="badge bg-secondary">低</span>
                        {% endif %}
                    </td>
                    <td>
                        {% if service.status == 'pending' %}
                            <span class="badge bg-warning">待处理</span>
                        {% elif service.status == 'processing' %}
                            <span class="badge bg-primary">处理中</span>
                        {% elif service.status == 'completed' %}
                            <span class="badge bg-success">已完成</span>
                        {% else %}
                            <span class="badge bg-secondary">已关闭</span>
                        {% endif %}
                    </td>
                    <td>{{ service.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
                    <td>
                        <a href="{{ url_for('service.service_edit', id=service.id) }}" class="btn btn-sm btn-primary">
                            <i class="fas fa-edit"></i> 编辑
                        </a>
                        <a href="{{ url_for('service.service_delete', id=service.id) }}" 
                           class="btn btn-sm btn-danger"
                           onclick="return confirm('确定要删除这条服务记录吗？');">
                            <i class="fas fa-trash"></i> 删除
                        </a>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {% if pagination.pages > 1 %}
    <nav aria-label="Page navigation">
        <ul class="pagination justify-content-center">
            {% for page in pagination.iter_pages() %}
                {% if page %}
                    <li class="page-item {% if page == pagination.page %}active{% endif %}">
                        <a class="page-link" href="{{ url_for('service.service_list', page=page, order_id=order_id, customer_name=customer_name, service_type=service_type, status=status) }}">{{ page }}</a>
                    </li>
                {% else %}
                    <li class="page-item disabled"><span class="page-link">...</span></li>
                {% endif %}
            {% endfor %}
        </ul>
    </nav>
    {% endif %}
</div>
{% endblock %} 